/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package components;

import java.awt.Color;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
import nemeanshop.Product;
import nemeanshop.Productlist;

/**
 *
 * @author havardaxelsen
 */
public class NTablemod extends AbstractTableModel{

    
    private ArrayList datalist = new ArrayList();
    private int col = this.getColumnCount();
    private int row = this.getRowCount();
    private String colname[] = { "String1" };
    private Productlist p;
    
    
   public NTablemod(Productlist productlist, String colname[])
    {
        this.p = productlist;
        this.datalist = p.getProductList();
        this.row = productlist.getProductListSize();
        this.colname = colname;
    }

    
    

    @Override
    public int getRowCount() {
        return datalist.size();
    }

    @Override
    public int getColumnCount() {
        return 4;
    }
    
    @Override
    public String getColumnName(int index){
        
        return (index>=0 && index<colname.length)
               ? colname[index].toString()
               :"";

    }
    
    @Override
    public Class getColumnClass(int c)
    {
        
        return getValueAt(0, c).getClass();
    }

    @Override
    public Object getValueAt(int i, int i1) {
        Product p = (Product) this.datalist.get(i);
        switch (i1) {
        case 0:
         return p.getProductName();
        case 1:
         return p.getSellPrice();
        case 2:
            ;
            return "Slett";
        case 3:
         return p.getInStore();
        default:
         return null;
   }
  }
    public void addProduct(Product p) {
   datalist.add(p);
   fireTableDataChanged();
  }
  
  public void addProductlist(Productlist l) {
   datalist.add(l);
   fireTableDataChanged();
  }
    }


